/**
 * @Version 1.0.0
 * @Author DemoHui
 * @Date 2022/09/28
 */

import axios from "axios";
import { Message } from "element-ui";

// 创建axios实例
const service = axios.create({
  baseURL: "http://47.109.79.105:8052", // api 的 base_url
  timeout: 10000, // 请求超时时间
});

// request拦截器
service.interceptors.request.use(
  (config) => {
    config.headers["Content-Type"] = "application/json;charset=utf-8";
    config.headers["Authorization"] =
      "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJhOTAwYTgzZTI0M2Y0N2NhOGM5NmNlZjhmNjliOGQyYiIsInVzZXIiOiJzemgiLCJzdWIiOiJzemgifQ.hWGAEmrJpL-4KbvqkBxH2v_BBuMpWMBzNKRGRn03cHmknMO1x2SltnIwsNAB-uDYC6gOa8mEifiV5PkD_6e3-A";
    return config;
  },
  (error) => {
    Message({
      message: error.message,
      type: "error",
    });
    return Promise.reject(error);
  }
);

// response 拦截器
service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    Message({
      message: error.message,
      type: "error",
    });
    return Promise.reject(error);
  }
);
export default service;
